import { AddRoleParams, RoleState } from '@/interfaces/api/role'
import { ResProps } from '@/interfaces/request'
import request from '@/utils/request'
import { AxiosPromise } from 'axios'

/**
 * @description: 拿到所有的角色
 */
export const selectRoleListApi = (): AxiosPromise<ResProps<RoleState[]>> => {
  return request({
    url: '/role/select',
    method: 'get',
  })
}

/**
 * @description: 根据角色名模糊查询角色列表
 */
export const likeRoleListApi = ({ key }: { key: string }): AxiosPromise<ResProps<RoleState[]>> => {
  return request({
    url: '/role/like',
    method: 'get',
    params: { key: key ? key : '' },
  })
}

export const updateRoleMenuApi = (data: { id: number; child: number[] }) => {
  return request({
    url: '/role/updateRole',
    method: 'post',
    data,
  })
}

export const updateRoleInfoApi = (data: RoleState) => {
  return request({
    url: '/role/updateRoleInfo',
    method: 'post',
    data,
  })
}

export const deleteRoleApi = ({ id }: { id: number }) => {
  return request({
    url: '/role/delete',
    method: 'post',
    params: { id: id },
  })
}

export const addRoleApi = (data: AddRoleParams) => {
  return request({
    url: '/role/add',
    method: 'post',
    data,
  })
}
